package main

import (
	"fmt"
	"sync"
	"time"
)

type Person struct {
	mu     sync.RWMutex
	salary int
	level  int
}

func (p *Person) promote() {
	p.mu.Lock()
	defer p.mu.Unlock()
	p.salary += 1000
	p.level += 1
	fmt.Println(p.salary, p.level)

}
func (p *Person) printLock() {
	p.mu.RLock()
	defer p.mu.RUnlock()
	fmt.Println("1")
	fmt.Println("printLock:", p.salary, p.level)
}
func main() {
	p := Person{level: 1, salary: 1000}
	onece := sync.Once{}
	go onece.Do(p.printLock)
	go onece.Do(p.printLock)

	onece2 := sync.Once{}

	go onece2.Do(p.printLock)
	go onece2.Do(p.printLock)
	time.Sleep(time.Second * 3)
}
